﻿using NHibernate;
using NHibernate.Criterion;
using Web.Entities;
using Web.Entities.Enums;

namespace Web.DataAccess
{
	public class InflectionQuery : IQuery<string>
	{
		public InflectionQuery(string normalForm, bool singular, Case @case)
		{
			this.normalForm = normalForm;
			this.singular = singular;
			this.@case = @case;
		}

		public string Load(ISession session)
		{
			var inflection = session.CreateCriteria<Inflection>()
				.Add(Restrictions.Eq("NormalForm", normalForm))
				.Add(Restrictions.Eq("Singular", singular))
				.Add(Restrictions.Eq("Case", @case))
				.UniqueResult<Inflection>();
			return inflection == null ? null : inflection.ResultForm;
		}

		private readonly string normalForm;
		private readonly bool singular;
		private readonly Case @case;
	}
}